<?php

class manageController extends AppController {


    public function initial($params) {
        $this->setDefaultModel();
        $this->view = new AppView();
        $this->setDefaultView();
        $this->setParams($this->var_trim($params));
        $WebSite=$this->getWebSite();
        $this->view->setVariable("WEBSITE", $WebSite);

    }



    function var_trim($arr) {
        $data = array();
        if (is_array($arr)) {
            foreach ($arr as $key => $value) {
                if (is_array($value)) {
                    $value = $this->var_trim($value);
                } else {
                    $value = trim($value);
                }
                $data[$key] = $value;
            }
        }
        return $data;
    }


    /**
     * @param $data 缺省数组
     */
    public function GetCompanys(array $data)
    {
        # 获取分司列表
        $where_fields_c = array("AND" => array("=" => array('is_parent' => 1, 'isdeleted' => 0)));
        $field_c = 'id,code,name';
        $CompanyLiist = $this->model->getAll($where_fields_c, 'xd_company', '', $field_c);
        $CompanyLiists = [];
        # 重构
        foreach ($CompanyLiist as $cval) {
            $CompanyLiists[$cval['code']] = $cval['name'];
        }
        return $CompanyLiists;
    }

    /**
     * @param $data 缺省数组
     */
    public function GetStores(array $data)
    {
        # 获取门店列表
        $where_fields = array("AND" => array("=" => array('isdeleted' => 0)));
        $field = 'id,store_id,storename,company_id';
        $storeLiist = $this->model->getAll($where_fields, 'xd_store', '', $field);
        $store_data = [];
        # 重构
        foreach ($storeLiist as $stoval) {
            $storeLiists[$stoval['store_id']] = $stoval['storename'];
            $store_data[$stoval['store_id']] =$stoval;
        }
        return ['store_data'=>$store_data,'storeLiists'=>$storeLiists];
    }


    /**
     * @param $data 缺省数组
     */
    public function GetSources(array $data)
    {
        # 订单来源、
        $where_fields_source = array("AND" => array("=" => array('status' => 1, 'isdeleted' => 0)));
        $field_source = 'id,source_name';
        $sourceList = $this->model->getAll($where_fields_source, 'zp_source', '', $field_source);

        foreach ($sourceList as $sourceval) {
            $sourceLists[$sourceval['id']] = $sourceval['source_name'];
        }
        $sourceLists = Data::$_orders_source + $sourceLists ;
        return $sourceLists;
    }


}
